﻿using System;

namespace LetterIndex
{
    class LetterIndex
    {
        //Our alphabet array
        static char[] alphabetLetters;
        static string word;

        static void PrintResult(int?[] result)
        {
            for (int index = 0, length = result.Length; index < length; index++)
            {
                //if the index is not found
                if (result[index] == null)
                {
                    continue;
                }
                Console.WriteLine("{0} => {1}", word[index], result[index]);
            }
        }

        static void GenerateAlphabetLetters()
        {
            alphabetLetters = new char[52];
            //Uppercase
            for (int index = 0, letterIndex = 65; index < 26; index++, letterIndex++)
            {
                alphabetLetters[index] = (char)letterIndex;
            }
            //Lowercase
            for (int index = 26, letterIndex = 97; index < 52; index++, letterIndex++)
            {
                alphabetLetters[index] = (char)letterIndex;
            }
        }

        static int?[] GetLetterIndex()
        {
            int?[] resultIndex = new int?[word.Length];
            for (int index = 0, length = word.Length; index < length; index++)
            {
                int currentIndex = 0;
                if (char.IsUpper(word, index))
                {
                    //B - A => 1
                    currentIndex = word[index] - 'A';
                }
                else
                {
                    currentIndex = (word[index] - 'a') + 26;
                }
                //Check if the letter is between 0 and 52
                if (currentIndex >= 0 && currentIndex < 52)
                {
                    resultIndex[index] = currentIndex;
                }
            }
            return resultIndex;
        }
        static void Main(string[] args)
        {
            int?[] resultIndex;
            GenerateAlphabetLetters();
            Console.Write("Enter a word [A-Z]: ");
            LetterIndex.word = Console.ReadLine();
            resultIndex = GetLetterIndex();
            PrintResult(resultIndex);
        }
    }
}
